from rest_framework.viewsets import ModelViewSet
from apps.goods.models import SPU, Brand, GoodsCategory
from apps.meiduo_admin.serializers.spu import SPUSerializer, BrandSerializer, FirstGategorySerializer
from apps.meiduo_admin.utils import PageNum
from rest_framework.generics import ListAPIView


class SPUListModelViewSet(ModelViewSet):
    queryset = SPU.objects.all()
    serializer_class = SPUSerializer
    pagination_class = PageNum


class BrandView(ListAPIView):
    queryset = Brand.objects.all()
    serializer_class = BrandSerializer


class FirstGategoryView(ListAPIView):
    """一级分类"""
    queryset = GoodsCategory.objects.filter(parent=None)
    serializer_class = FirstGategorySerializer


class SeThGategoryView(ListAPIView):
    """二三级分类"""
    # 序列化器可以用之前定义的
    serializer_class = FirstGategorySerializer

    def get_queryset(self):
        pk = self.kwargs['pk']
        return GoodsCategory.objects.filter(parent=pk)
